package com.example.lotterysystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.lotterysystem.dao.dataobject.WinningRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface WinningRecordMapper extends BaseMapper<WinningRecord> {
    @Insert("<script> insert into winning_record (activity_id, activity_name, prize_id, prize_name, prize_tier," +
            " winner_id, winner_name, winner_email, winner_phone_number, winning_time)" +
            " values <foreach collection = 'items' item = 'item' index = 'index' separator=','>" +
            " (#{item.activityId}, #{item.activityName}, #{item.prizeId}, #{item.prizeName}, #{item.prizeTier}, " +
            " #{item.winnerId}, #{item.winnerName}, #{item.winnerEmail}, #{item.winnerPhoneNumber}, #{item.winningTime})" +
            " </foreach>" + " </script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer batchInsert(@Param("items") List<WinningRecord> winningRecordList);
}
